package cn.com.api.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiT_enums;
import cn.com.api.entity.ApiT_member;
import cn.com.api.entity.ApiT_order;
import cn.com.api.entity.ApiT_order_detail;
import cn.com.api.entity.ApiU_coupon;
import cn.com.api.service.ApiNewFindOrderService;
import cn.com.api.service.ApiT_enumsService;
import cn.com.api.service.ApiT_memberService;
import cn.com.api.service.ApiU_couponService;
import cn.com.api.service.CheckService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "u_coupon/")
public class ApiU_couponController {
	@Autowired
	private ApiU_couponService apiU_couponService;

	@Autowired
	private CheckService checkService;

	@Autowired
	private ApiT_enumsService apiT_enumsService;

	@Autowired
	private ApiNewFindOrderService apiNewFindOrderService;

	@Autowired
	private ApiT_memberService memberService;

	private static Logger logger = Logger.getLogger(ApiU_couponController.class);

	/**
	 * 根据优惠券类型查询优惠券列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("findU_coupons-list")
	public void findU_coupons_list(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String coupon_cate_id = request.getParameter("coupon_cate_id");
			String orderBy = request.getParameter("orderBy");
			String latitude = request.getParameter("latitude");
			String longitude = request.getParameter("longitude");

			List<ApiT_enums> cate = apiT_enumsService.findT_enumssByItem_key("coupon_classify");
			List<ApiT_enums> cate_list = apiT_enumsService.findT_enumssByParent_id(cate.get(0).getId() + "");
			Map<String, Object> cateMap = new HashMap<String, Object>();
			List<Map<String, Object>> catelistMap = new ArrayList<Map<String, Object>>();
			for (ApiT_enums apiT_enums : cate_list) {
				cateMap = new HashMap<String, Object>();
				cateMap.put("item_value", apiT_enums.getItem_value());
				cateMap.put("item_name", apiT_enums.getDisplay_name());
				catelistMap.add(cateMap);
			}

			Map<String, Object> result = new HashMap<String, Object>();
			result.put("cate_list", catelistMap);

			List<ApiT_enums> coupon = apiT_enumsService.findT_enumssByItem_key("coupon_preferential");
			List<ApiT_enums> coupon_list = apiT_enumsService.findT_enumssByParent_id(coupon.get(0).getId() + "");
			Map<String, Object> couMap = new HashMap<String, Object>();
			List<Map<String, Object>> couponlistMap = new ArrayList<Map<String, Object>>();
			for (ApiT_enums apiT_enums : coupon_list) {
				couMap = new HashMap<String, Object>();
				couMap.put("item_value", apiT_enums.getItem_value());
				couMap.put("item_name", apiT_enums.getDisplay_name());
				couponlistMap.add(couMap);
			}

			result.put("coupon_list", catelistMap);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("user_id", user_id);
			params.put("token", token);
			params.put("coupon_cate_id", coupon_cate_id);
			params.put("orderBy", orderBy);
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			/* if(checkService.checkToken(user_id, token, map)){ */
			Map<String, Object> couponMap = new HashMap<String, Object>();
			List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
			List<ApiU_coupon> u_coupons = apiU_couponService.findU_coupons_info(params);
			for (ApiU_coupon apiU_coupon : u_coupons) {
				couponMap = new HashMap<String, Object>();
				couponMap.put("corp_name", apiU_coupon.getCorp_name());
				couponMap.put("distance", apiU_coupon.getDistance());
				couponMap.put("coupon_id", apiU_coupon.getCoupon_id());
				couponMap.put("coupon_detail_id", apiU_coupon.getCoupon_detail_id());
				couponMap.put("corp_adress", apiU_coupon.getCorp_adress());
				couponMap.put("end_time", apiU_coupon.getEnd_time());
				couponMap.put("range", apiU_coupon.getRange());
				couponMap.put("coupon_amout", apiU_coupon.getCoupon_amout());
				couponMap.put("coupon_img", apiU_coupon.getCoupon_img());
				listMap.add(couponMap);
			}
			result.put("coupon_list", listMap);
			map.put("datas", result);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
			// }

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 我发布的优惠券
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_coupons-mine")
	public void findU_coupons_mine(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("user_id", user_id);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> couponMap = new HashMap<String, Object>();
				List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
				List<ApiU_coupon> u_coupons = apiU_couponService.findU_couponsByUserid(params);
				for (ApiU_coupon apiU_coupon : u_coupons) {
					couponMap = new HashMap<String, Object>();
					couponMap.put("corp_name", apiU_coupon.getCorp_name());
					couponMap.put("coupon_id", apiU_coupon.getCoupon_id());
					couponMap.put("corp_adress", apiU_coupon.getCorp_adress());
					couponMap.put("end_time", apiU_coupon.getEnd_time());
					couponMap.put("range", apiU_coupon.getRange());
					couponMap.put("coupon_amout", apiU_coupon.getCoupon_amout());
					couponMap.put("coupon_img", apiU_coupon.getCoupon_img());
					listMap.add(couponMap);
				}
				map.put("datas", listMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

			// return
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 根据优惠券ID查询优惠券详情
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_coupons-detail")
	public void findU_coupons_detail(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String coupon_id = request.getParameter("coupon_id");

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("coupon_id", coupon_id);
			params.put("user_id", user_id);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> couponMap = new HashMap<String, Object>();
				ApiU_coupon u_coupons = apiU_couponService.findU_couponsDetailByCouponid(params);
				couponMap.put("area", u_coupons.getArea());
				couponMap.put("city", u_coupons.getCity());
				couponMap.put("province", u_coupons.getProvince());
				couponMap.put("corp_mobile", u_coupons.getCorp_mobile());
				couponMap.put("coupon_img", u_coupons.getCoupon_img());
				couponMap.put("description", u_coupons.getDescription());
				couponMap.put("business_hours", u_coupons.getBusiness_hours());
				couponMap.put("corp_name", u_coupons.getCorp_name());
				couponMap.put("corp_img", u_coupons.getCorp_img());
				couponMap.put("coupon_amout", u_coupons.getCoupon_amout());
				couponMap.put("coupon_id", u_coupons.getCoupon_id());
				couponMap.put("use_limit1", u_coupons.getUse_limit1());

				couponMap.put("corp_adress", u_coupons.getCorp_adress());
				couponMap.put("end_time", u_coupons.getEnd_time());

				map.put("datas", couponMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 发布优惠券
	 */
	@Transactional
	@RequestMapping(value = "findU_coupon-publish")
	public void findU_coupon_publish(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			Map<String, Object> param = new HashMap<String, Object>();
			if (checkService.checkToken(user_id, token, map)) {
				String coupon_cate_id = request.getParameter("coupon_cate_id"); // 优惠券分类
				String corp_name = request.getParameter("corp_name"); // 公司名称
				String corp_adress = request.getParameter("corp_adress"); // 公司位置
				String range = request.getParameter("range"); // 投放范围
				String corp_mobile = request.getParameter("corp_mobile"); // 联系电话
				String business_hours = request.getParameter("business_hours"); // 营业时间
				String coupon_type = request.getParameter("coupon_type"); // 优惠类型
				String description = request.getParameter("description"); // 优惠券说明
				String province = request.getParameter("province"); // 省
				String city = request.getParameter("city"); // 市
				String area = request.getParameter("area"); // 地区

				String deposit_amount = request.getParameter("deposit_amount");
				if (deposit_amount == null || "".equals(deposit_amount)) {

					deposit_amount = "0";
				}

				String coupon_amout = request.getParameter("coupon_amout"); // 优惠金额
				String use_limit1 = request.getParameter("use_limit1"); // 使用条件
				String coupon_count = request.getParameter("coupon_count"); // 发放数量
				String end_time = request.getParameter("end_time"); // 有效期至
				String begin_time = request.getParameter("begin_time"); // 有效期至

				String[] coupon_amout_list = null;
				String[] use_limit1_list = null;
				String[] coupon_count_list = null;
				String[] end_time_list = null;
				String[] start_time_list = null;

				if (coupon_amout != null && !coupon_amout.equals("")) {
					coupon_amout_list = coupon_amout.split("@@");// 费用明细：多条，每条之间用@#@分隔开
				}

				if (use_limit1 != null && !use_limit1.equals("")) {
					use_limit1_list = use_limit1.split("@@");// 费用明细：多条，每条之间用@#@分隔开
				}

				if (coupon_count != null && !coupon_count.equals("")) {
					coupon_count_list = coupon_count.split("@@");// 费用明细：多条，每条之间用@#@分隔开
				}

				if (end_time != null && !end_time.equals("")) {
					end_time_list = end_time.split("@@");// 费用明细：多条，每条之间用@#@分隔开
				}

				if (begin_time != null && !begin_time.equals("")) {
					start_time_list = begin_time.split("@@");// 费用明细：多条，每条之间用@#@分隔开
				}

				logger.info("======[U_couponController[u_coupon_add[参数coupon_cate_id:" + coupon_cate_id + ",corp_name:"
						+ corp_name + ",corp_adress:" + corp_adress + "]]]=======");
				logger.info("======[U_couponController[u_coupon_add[参数range:" + range + ",corp_mobile:" + corp_mobile
						+ ",business_hours:" + business_hours + ",coupon_type:" + coupon_type + "]]]=======");
				logger.info("======[U_couponController[u_coupon_add[参数description:" + description + ",coupon_amout:"
						+ coupon_amout + ",use_limit1:" + use_limit1 + ",coupon_count:" + coupon_count + ",end_time:"
						+ end_time + "]]]=======");

				SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String create_time = sd.format(new Date());

				// 判断优惠金额有多少条
				int coupon_length = 0;
				if (coupon_amout != null) {
					coupon_length = coupon_amout_list.length;
				}

				ApiU_coupon u_coupon = new ApiU_coupon();
				u_coupon.setUser_id(user_id);
				u_coupon.setIs_active(1);

				u_coupon.setCorp_adress(corp_adress);
				u_coupon.setCoupon_cate_id(coupon_cate_id);
				u_coupon.setCorp_name(corp_name);
				u_coupon.setCorp_adress(corp_adress);
				u_coupon.setRange(Long.parseLong(range));
				u_coupon.setCorp_mobile(corp_mobile);
				u_coupon.setBusiness_hours(business_hours);
				u_coupon.setCoupon_type(Integer.parseInt(coupon_type));
				u_coupon.setDescription(description);
				u_coupon.setCity(city);
				u_coupon.setProvince(province);
				u_coupon.setArea(area);
				u_coupon.setCreate_time(create_time);
				if (coupon_length >= 1) {
					for (int i = 0; i < coupon_length; i++) {
						param = new HashMap<String, Object>();
						param.put("coupon_amout", Integer.parseInt(coupon_amout_list[i]));
						param.put("use_limit1", use_limit1_list[i]);
						param.put("coupon_count", Long.parseLong(coupon_count_list[i]));
						param.put("end_time", end_time_list[i]);
						param.put("start_time", start_time_list[i]);
						param.put("deposit_amount",
								Integer.parseInt(coupon_amout_list[i]) * Long.parseLong(coupon_count_list[i]));
						list.add(param);
					}
				}
				List<Object> ly = apiU_couponService.insertU_coupon_info(u_coupon, list);
				String result_id = "";
				for (Object object : ly) {
					result_id += object + ",";
				}
				if (result_id.length() > 1 && result_id.indexOf(",") != -1) {
					result_id = result_id.substring(0, result_id.length() - 1);
				}

				String ordernum = Utils.getDingDanNo("");// 订单号

				ApiT_member apiT_member = memberService.findMemberByCid(user_id);

				if (apiT_member == null) {
					map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
					map.put(Utils.MESSAGE, "用户不存在！");
				} else {
					ApiT_order apiT_order = new ApiT_order();
					if (apiT_member.getC_address() == null) {
						apiT_order.setAddress("");
					} else {
						apiT_order.setAddress(apiT_member.getC_address() + "");
					}
					apiT_order.setShop_id("");
					apiT_order.setUser_id(user_id + "");
					apiT_order.setC_avatar(apiT_member.getC_avatar() + "");
					apiT_order.setDd_status(1);
					apiT_order.setMoney(new BigDecimal(deposit_amount));
					apiT_order.setZf_type(0 + "");
					apiT_order.setOrdernum(ordernum);
					apiT_order.setSerialflagno(ordernum);
					apiT_order.setName(apiT_member.getC_cname() + "");
					apiT_order.setMobile(apiT_member.getC_mob() + "");
					apiT_order.setTitles("优惠券押金订单" + new Date().getTime() + "");
					apiT_order.setOrdertype(9);
					apiT_order.setName(apiT_member.getC_cname());

					apiU_couponService.insertU_coupon_order(apiT_order);

					ApiT_order_detail apiT_order_detail = new ApiT_order_detail();
					apiT_order_detail.setDid(ordernum);
					apiT_order_detail.setNum(1);
					apiT_order_detail.setMoney(new BigDecimal(deposit_amount));
					apiT_order_detail.setTarget_id(result_id);
					apiT_order_detail.setProduct_id(result_id);
					apiT_order_detail.setExt_1("");
					apiT_order_detail.setExt_2("");
					apiT_order_detail.setExt_3("");
					apiT_order_detail.setExt_4("");
					apiT_order_detail.setPoints(0);
					apiT_order_detail.setStore(0);
					apiU_couponService.insertU_coupon_order_detail(apiT_order_detail);

					Map<String, Object> couponMap = new HashMap<String, Object>();
					couponMap.put("ordernum", ordernum);
					couponMap.put("coupon_id_list", result_id);
					map.put("datas", couponMap);
					map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
					map.put(Utils.MESSAGE, "发布优惠券成功！");
				}
			}
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "发布优惠券失败！");
			logger.error("======[U_couponController[u_coupon_add[发布优惠券失败]]]=========", e);
		}
		//
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 优惠买单
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_coupons-buy")
	public void findU_coupons_buy(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String coupon_id = request.getParameter("coupon_id");
			String pay_type = request.getParameter("pay_type");
			long buy_amount = Long.parseLong(request.getParameter("buy_amount"));

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("coupon_id", coupon_id);
			params.put("buy_amount", buy_amount);
			params.put("pay_type", pay_type);
			params.put("user_id", user_id);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {

				map = apiU_couponService.findU_coupons_buy(params);
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 优惠买单页面查询账户余额
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_coupons-buy-info")
	public void findU_coupons_buy_info(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> result = new HashMap<String, Object>();
		try {

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("user_id", user_id);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {
				long balance = apiNewFindOrderService.queryUserMoney(user_id);
				result.put("balance", balance);
				map.put("datas", result);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	@RequestMapping(value = "add_coupons_order")
	public void add_coupons_order(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String money = request.getParameter("money");// 总金额
			String shop_id = request.getParameter("shop_id");// 店铺ID
			String title = request.getParameter("title");// 订单名称
			String ordernum = Utils.getDingDanNo("");// 订单号
			String paymoney = request.getParameter("paymoney");// 优惠后金额
			String coupon_detail_id = request.getParameter("coupon_detail_id");// 优惠劵ID

			ApiT_member apiT_member = memberService.findMemberByCid(user_id);

			ApiT_order apiT_order = new ApiT_order();
			if (apiT_member.getC_address() == null) {
				apiT_order.setAddress("");
			} else {
				apiT_order.setAddress(apiT_member.getC_address() + "");
			}
			apiT_order.setShop_id(shop_id);
			apiT_order.setUser_id(user_id + "");
			apiT_order.setC_avatar(apiT_member.getC_avatar() + "");
			apiT_order.setDd_status(1);
			apiT_order.setMoney(new BigDecimal(money));
			apiT_order.setZf_type(0 + "");
			apiT_order.setOrdernum(ordernum);
			apiT_order.setSerialflagno(ordernum);
			apiT_order.setName(apiT_member.getC_cname() + "");
			apiT_order.setMobile(apiT_member.getC_mob() + "");
			apiT_order.setTitles(title);
			apiT_order.setOrdertype(10);
			apiT_order.setPaymoney(new BigDecimal(paymoney));
			apiT_order.setName(apiT_member.getC_cname());

			apiU_couponService.insertU_coupon_order(apiT_order);

			ApiT_order_detail apiT_order_detail = new ApiT_order_detail();
			apiT_order_detail.setDid(ordernum);
			apiT_order_detail.setNum(1);
			apiT_order_detail.setMoney(new BigDecimal(paymoney));
			apiT_order_detail.setTarget_id(coupon_detail_id + "");
			apiT_order_detail.setProduct_id(coupon_detail_id + "");
			apiT_order_detail.setExt_1("");
			apiT_order_detail.setExt_2("");
			apiT_order_detail.setExt_3("");
			apiT_order_detail.setExt_4("");
			apiT_order_detail.setPoints(0);
			apiT_order_detail.setStore(0);
			apiU_couponService.insertU_coupon_order_detail(apiT_order_detail);

			Map<String, Object> couponMap = new HashMap<String, Object>();
			couponMap.put("ordernum", ordernum);
			map.put("datas", couponMap);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "优惠券支付订单生成成功！");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("========[ApiU_couponController[add_coupons_order]]错误=======", e);
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 修改优惠券支付状态
	 * 
	 * @param request
	 * @param response
	 * @param user_id
	 * @param token
	 * @throws Exception
	 */
	@RequestMapping(value = "upd_coupons_status")
	public void upd_coupons_status(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String coupon_id_list = request.getParameter("coupon_id_list");// 优惠券id列表
			apiU_couponService.upd_coupons_status(coupon_id_list);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "优惠券支付状态更新成功！");
		} catch (Exception e) {
			logger.error("========[ApiU_couponController[upd_coupons_status]]错误=======", e);
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 获取优惠券分类
	 * 
	 * @param request
	 * @param response
	 * @param user_id
	 * @param token
	 * @throws Exception
	 */
	@RequestMapping("findU_coupons_cate-list")
	public void findU_coupons_cate_list(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {

			List<ApiT_enums> cate = apiT_enumsService.findT_enumssByItem_key("coupon_classify");
			List<ApiT_enums> cate_list = apiT_enumsService.findT_enumssByParent_id(cate.get(0).getId() + "");
			Map<String, Object> cateMap = new HashMap<String, Object>();
			List<Map<String, Object>> catelistMap = new ArrayList<Map<String, Object>>();
			for (ApiT_enums apiT_enums : cate_list) {
				cateMap = new HashMap<String, Object>();
				cateMap.put("item_value", apiT_enums.getItem_value());
				cateMap.put("item_name", apiT_enums.getDisplay_name());
				catelistMap.add(cateMap);
			}

			Map<String, Object> result = new HashMap<String, Object>();
			result.put("cate_list", catelistMap);

			map.put("datas", result);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	@RequestMapping("findU_coupons_order-list")
	public void findU_coupons_order_list(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> param = new HashMap<String, Object>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {

			String status = request.getParameter("status");
			String ordertype = request.getParameter("order_type");
			param.put("user_id", user_id);
			param.put("status", status);
			param.put("ordertype", ordertype);

			List<Map<String, Object>> list = apiU_couponService.getOrdersList(param);
			List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
			for (Map<String, Object> map2 : list) {
				resultMap.put("ordernum", map2.get("ORDERNUM"));
				resultMap.put("titles", map2.get("TITLES"));
				resultMap.put("money", map2.get("MONEY"));
				resultMap.put("paymoney", map2.get("PAYMONEY"));
				resultMap.put("zi_status", map2.get("ZI_STATUS"));
				resultMap.put("use_time", map2.get("USE_TIME"));
				resultMap.put("status", map2.get("STATUS"));
				resultMap.put("ordernum", map2.get("USE_TIME"));
				resultMap.put("corp_address", map2.get("CORP_ADDRESS"));
				resultMap.put("corp_name", map2.get("CORP_NAME"));
				resultMap.put("coupon_img", map2.get("COUPON_IMG"));
				resultMap.put("price", map2.get("PRICE"));
				resultMap.put("num", map2.get("NUM"));
				resultMap.put("c_nick", map2.get("C_NICK"));
				resultMap.put("c_avatar", map2.get("C_AVATAR"));
				resultList.add(resultMap);

			}
			map.put("datas", resultList);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

}
